import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { User } from '../types/user.d'

export const useUserStore = defineStore(
  'user',
  () => {
    // 1.用户信息
    const user = ref<User>()

    // 2.修改数据
    const setUser = (u: User) => (user.value = u)

    // 3.删除数据
    const delUser = () => (user.value = undefined)

    // 4.保存地址
    const returnUrl = ref('')
    const setReturnUrl = (url: string) => (returnUrl.value = url)

    return { user, setUser, delUser, setReturnUrl, returnUrl }
  },
  {
    persist: true
  }
)
